<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateProviderAuthorizationTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        // 创建一个授权关系表，用于关联供应商和采购商
        Schema::dropIfExists('provider_purchaser');
        Schema::create('provider_purchaser', function(Blueprint $blueprint) {
            $blueprint->integer('provider_id')->unsigned()->commnet('供应商 ID');
            $blueprint->integer('purchaser_id')->unsgined()->comment('采购商 ID');

            // 创建主键
            $blueprint->primary(['provider_id', 'purchaser_id']);
        });

        Schema::table('goods', function(Blueprint $blueprint) {
            $blueprint->string('spec_father_name')->nullable()->comment('自定义商品规格字段名 1')->change();
            $blueprint->string('spec_som_name')->nullable()->comment('自定义商品规格字段名 2')->change();
            $blueprint->string('spec_third_name')->nullable()->comment('自定义商品规格字段名 3');
            $blueprint->string('spec_forth_name')->nullable()->comment('自定义商品规格字段名 4');
            $blueprint->string('spec_fifth_name')->nullable()->comment('自定义商品规格字段名 4');
        });

        Schema::table('goods', function(Blueprint $blueprint) {
            $blueprint->renameColumn('spec_father_name', 'spec_first_name');
            $blueprint->renameColumn('spec_som_name', 'spec_second_name');

            $blueprint->dropColumn('weight');
            $blueprint->string('unit')->comment('单位');
        });

        Schema::table('goods_specifications', function(Blueprint $blueprint) {
            $blueprint->renameColumn('spec_father_name', 'spec_first');
            $blueprint->renameColumn('spec_som_name', 'spec_second');

            $blueprint->string('spec_third')->comment('自定义商品规格字段名 3');
            $blueprint->string('spec_forth')->comment('自定义商品规格字段名 4');
            $blueprint->string('spec_fifth')->comment('自定义商品规格字段名 4');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        //
    }
}
